package com.yunfeng.supercall.manager;

import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.yunfeng.supercall.R;
import com.yunfeng.supercall.activity.AdsDetailActivity;
import com.yunfeng.supercall.bean.AdsBean;
import com.yunfeng.supercall.bean.Constants;

/**
 * 管理广告
 * 
 * @author 洋
 * 
 */
public class AdsManager extends ManagerBaseIface<AdsBean> {

	public void addAdsHeader(final View listView, final int index) {
		if (mList == null || mList.isEmpty()) {
			return;
		}
		View header = LayoutInflater.from(listView.getContext()).inflate(
				R.layout.list_header_ads, (ViewGroup) listView, false);
		header.setBackgroundColor(Color.rgb(202, 220, 227));
		header.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				listView.getContext().startActivity(
						new Intent(listView.getContext(),
								AdsDetailActivity.class).putExtra(
								Constants.KEY_DATA,
								mList.get(index % mList.size()).getUrl())
								.putExtra(
										Constants.KEY_PHONE,
										mList.get(index % mList.size())
												.getTitle()));
			}
		});
		TextView content = (TextView) header.findViewById(R.id.content);
		content.setSelected(true);
		content.setText(mList.get(index % mList.size()).getTitle());
		if (listView instanceof ListView) {
			((ListView) listView).addHeaderView(header, null, false);
		}
	}

}
